import {defineConfig, loadEnv} from 'vite';
import vue from '@vitejs/plugin-vue';

import AutoImport from 'unplugin-auto-import/vite';
import {createSvgIconsPlugin} from 'vite-plugin-svg-icons';

import path from 'path';
const pathSrc = path.resolve(__dirname, 'src');

import UnoCSS from 'unocss/vite';

export default defineConfig(({mode}) => {
  const env = loadEnv(mode, process.cwd());

  return {
    server: {
      host: '0.0.0.0', 
      port: Number(env.VITE_APP_PORT)
    },
    plugins: [
      vue(),
      UnoCSS(),
      AutoImport({
        include: [/\.[tj]sx?$/, /\.vue$/],
        imports: ['vue', 'vue-router', '@vueuse/core'],
        vueTemplate: true,
      }),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(pathSrc, 'assets/icons')],
        symbolId: 'icon-[dir]-[name]',
      })
    ],
    resolve: {
      alias: {
        '@': pathSrc,
        'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: `
            @use "@/styles/variables.scss" as *;
          `
        }
      }
    }
  };
});
